$(function () {
    clearInterval(timer);
    //获取需要的元素
    var $ban=$('.banner_lbt');
    var $lis=$('.banner_lbt>ul>li');
    var $cirs=$('.circle>span');
    var $arrow=$('.arrow');
    var $lt=$('.arrow-lt');
    var $rt=$('.arrow-rt');
    var count=0;//同步索引
    /*小方块*/
    $cirs.mouseenter(function () {
        count=$(this).index();
        change();
    });
    //上一张
    $lt.click(function () {
        count--;
        change();
    });
    //下一张
    $rt.click(nextPlay);
    //自动播放
    var timer=setInterval(nextPlay,3000);
    //鼠标移入和移出
    $ban.mouseenter(function () {
        $arrow.stop().fadeIn(400);
        clearInterval(timer);
    }).mouseleave(function () {
        clearInterval(timer);
        $arrow.stop().fadeOut(400);
        timer=setInterval(nextPlay,3000);
    });


    function change() {
        if(count==-1){
            count=$lis.length-1;
        }
        if(count==$lis.length){
            count=0;
        }
        $cirs.eq(count).addClass('current').siblings().removeClass('current');
        $lis.eq(count).stop().fadeIn(400).siblings().stop().fadeOut(400);
    }
    function nextPlay() {
        count++;
        change();
    }
});